//
//  OrderFooterTopCouponFreightView.m
//  FD
//
//  Created by xiaofang wang on 2019/1/8.
//  Copyright © 2019年 ZhiYuan Network. All rights reserved.
//

#import "OrderFooterTopCouponFreightView.h"

@interface OrderFooterTopCouponFreightView()
/**div1*/
@property (nonatomic, strong) UIView *div1;
/**优惠券文字*/
@property (nonatomic, strong) UILabel *couponTitleLb;
/**优惠券*/
@property (nonatomic, strong) UILabel *couponPricelLb;
/**线1*/
@property (nonatomic, strong) UIView *line1;


//===============
/**div2*/
@property (nonatomic, strong) UIView *div2;
/**配送费文字*/
@property (nonatomic, strong) UILabel *freightTitleLb;
/**配送费*/
@property (nonatomic, strong) UILabel *freightPriceLb;
/**线2*/
@property (nonatomic, strong) UIView *line2;

//===============
/**div3*/
@property (nonatomic, strong) UIView *div3;
/**已优惠€4.0 灰色显示*/
@property (nonatomic, strong) UILabel *alreadyYouHuiLb;
/**合计:€666*/
@property (nonatomic, strong) UILabel *sumLb;



/**divArr 方便一次性布局*/
@property (nonatomic, strong) NSArray *divArr;
@end


@implementation OrderFooterTopCouponFreightView

#pragma mark - init
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    if (self) {
        [self setupUI];
        
        self.backgroundColor = kMainLightGrayColor;
    }
    return self;
}
- (void)setupUI {
    [self addSubview:self.div1];
    [self addSubview:self.div2];
    [self addSubview:self.div3];
    
    self.divArr = @[self.div1,self.div2,self.div3];
    
    
    [self.div1 addSubview:self.couponTitleLb];
    [self.div1 addSubview:self.couponPricelLb];
    [self.div1 addSubview:self.line1]; //线
    
    [self.div2 addSubview:self.freightTitleLb];
    [self.div2 addSubview:self.freightPriceLb];
    [self.div2 addSubview:self.line2]; //线
    
    [self.div3 addSubview:self.alreadyYouHuiLb];
    [self.div3 addSubview:self.sumLb];
}


#pragma mark - 接口 设置数据
- (void)setDataWithCoupon:(NSNumber *)coupon freight:(NSNumber *)freight alreadCoupon:(CGFloat)alreadyCoupon sum:(NSNumber *)sum {

    self.couponPricelLb.text = [NSString stringWithFormat:@"-€%.1f",[coupon floatValue]];
    self.freightPriceLb.text = [NSString stringWithFormat:@"€%.1f",[freight floatValue]];
    
    NSString *yjyhStr = NSLocalizedString(L_Order_YiJinYouHui, @"已经优惠");
    NSString *hjStr = NSLocalizedString(Total, @"合计");
    self.alreadyYouHuiLb.text = [NSString stringWithFormat:@"%@:€%.1f",yjyhStr,alreadyCoupon];
    self.sumLb.text = [NSString stringWithFormat:@"%@:€%.1f",hjStr,[sum floatValue]];
}


#pragma mark - layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    //因为不是全屏的,中间单独添加的线, ∴ 不要间距
    [self.divArr mas_distributeViewsAlongAxis:(MASAxisTypeVertical) withFixedSpacing:0 leadSpacing:0 tailSpacing:8];
    [self.divArr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
    }];
    
    [self layoutDiv1];
    [self layoutDiv2];
    [self layoutDiv3];
}


//!!!!:layout div1
- (void)layoutDiv1 {
    [self.couponTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div1.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(120, 30));
        make.centerY.equalTo(self.div1.mas_centerY);
    }];
    [self.couponPricelLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.div1.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(120, 30));
        make.centerY.equalTo(self.div1.mas_centerY);
    }];
    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div1.mas_left).offset(15);
        make.right.equalTo(self.div1.mas_right).offset(-15);
        make.bottom.equalTo(self.div1.mas_bottom);
        make.height.mas_equalTo(1);
    }];
}


//!!!!:layout div2
- (void)layoutDiv2 {
    [self.freightTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div2.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(120, 30));
        make.centerY.equalTo(self.div2);
    }];
    [self.freightPriceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.div2.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(120, 30));
        make.centerY.equalTo(self.div2.mas_centerY);
    }];
    [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div2.mas_left).offset(15);
        make.right.equalTo(self.div2.mas_right).offset(-15);
        make.bottom.equalTo(self.div2.mas_bottom);
        make.height.mas_equalTo(1);
    }];
}

//!!!!:layout div3
- (void)layoutDiv3 {
    
    //已优惠
    [self.alreadyYouHuiLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.sumLb.mas_left).offset(-6);
        make.width.mas_greaterThanOrEqualTo(100);
        make.centerY.equalTo(self.div3);
        make.height.mas_equalTo(30);
    }];
    
    //合计:€666.6
    [self.sumLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.div3.mas_right).offset(-15);
        make.width.mas_greaterThanOrEqualTo(60);
        make.centerY.equalTo(self.div3);
        make.height.mas_equalTo(30);
    }];
}


#pragma mark - getter
//!!!!:div1
- (UIView *)div1 {
    if (!_div1) {
        _div1 = [UIView new];
        _div1.backgroundColor = [UIColor whiteColor];
    }
    return _div1;
}
- (UILabel *)couponTitleLb {
    if (!_couponTitleLb) {
        _couponTitleLb = [[UILabel alloc] init];
        _couponTitleLb.text = NSLocalizedString(Coupon, @"优惠券");
        _couponTitleLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _couponTitleLb;
}

- (UILabel *)couponPricelLb {
    if (!_couponPricelLb) {
        _couponPricelLb = [[UILabel alloc] init];
        _couponPricelLb.text = @"-€0.0";
        _couponPricelLb.textAlignment = NSTextAlignmentRight;
        _couponPricelLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _couponPricelLb;
}
- (UIView *)line1 {
    if (!_line1) {
        _line1 = [UIView new];
        _line1.backgroundColor = kMainLightGrayColor;
    }
    return _line1;
}


//!!!!:div2
- (UIView *)div2 {
    if (!_div2) {
        _div2 = [UIView new];
        _div2.backgroundColor = [UIColor whiteColor];
    }
    return _div2;
}
- (UILabel *)freightTitleLb {
    if (!_freightTitleLb) {
        _freightTitleLb = [UILabel new];
        _freightTitleLb.text = NSLocalizedString(OrderDistribution, @"配送费");
        _freightTitleLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _freightTitleLb;
}


- (UILabel *)freightPriceLb {
    if (!_freightPriceLb) {
        _freightPriceLb = [UILabel new];
        _freightPriceLb.text = @"€6.0";
        _freightPriceLb.textAlignment = NSTextAlignmentRight;
        _freightPriceLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _freightPriceLb;
}
- (UIView *)line2 {
    if (!_line2) {
        _line2 = [UIView new];
        _line2.backgroundColor = kMainLightGrayColor;
    }
    return _line2;
}


//!!!!:div3
- (UIView *)div3 {
    if (!_div3) {
        _div3 = [UIView new];
        _div3.backgroundColor = [UIColor whiteColor];
    }
    return _div3;
}

- (UILabel *)alreadyYouHuiLb {
    if (!_alreadyYouHuiLb) {
        _alreadyYouHuiLb = [[UILabel alloc] init];
        _alreadyYouHuiLb.textColor = kLightGrayTextColor;
        _alreadyYouHuiLb.textAlignment = NSTextAlignmentRight;
        _alreadyYouHuiLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _alreadyYouHuiLb;
}

- (UILabel *)sumLb {
    if (!_sumLb) {
        _sumLb = [UILabel new];
        _sumLb.textAlignment = NSTextAlignmentRight;
        _sumLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _sumLb;
}

@end
